(function($){
	var methods={
			init:function(options){
		         var that=this;
		         $("#"+that.attr("id")).after("<input type='hidden' class='imageName' name='"+that.attr("name")+"'/>");
		         $(this).uploadify({
		         	auto:options.auto||true,
		            swf: ""+methods.getRootPath()+"/js/uploadify/uploadify.swf",
		            uploader:options.uploader||methods.getRootPath()+"/uploadifyMethod",
		            fileObjName:options.fileObjName||"uploadImage",
		            formData:options.formData||{},
		            buttonText:options.buttonText||"选择图片",
		            fileSizeLimit:options.fileSizeLimit||"1MB",
		            fileTypeExts:options.fileTypeExts||'*.jpg;*.jpeg;*.pang',
		            onUploadSuccess:options.onUploadSuccess||function(file, data, response){
		            	
		        	    var rootDome=$("#"+that.attr("id"));
		                var img=$("<img>");
		                img.attr("src",""+methods.getRootPath()+"/"+options.formData.path+"/"+$.parseJSON(data).uploadImageFileName);
		                img.attr("style","height: 70px;width: 70px;");
		                var input=$(".imageName");
		                var value=input.val();
		                if(value==""){
		                	input.val($.parseJSON(data).uploadImageFileName);
		                }else{
		                	input.val(value+","+$.parseJSON(data).uploadImageFileName);
		                }
		                rootDome.after(img)
		            }
		        });
	         },
	         getRootPath:function(){
	            var curWwwPath=window.document.location.href;
	            var pathName=window.document.location.pathname;
	            var pos=curWwwPath.indexOf(pathName);
	            var localhostPaht=curWwwPath.substring(0,pos);
	            var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
	            return(localhostPaht+projectName);
	         }
	}
	
	/**
	 * 必填参数
	 * basePath 系统路径
	 * formData 图片保存文件夹
	 * 可选参数
	 * uploader 上传路径
	 * !!fileObjName 上传文件名(现已限定死)
	 * onUploadSuccess
	 * 创建的input的name是uploadifyInput
	 * **/
	$.fn.uploadifyHander=function(param){
		methods.init.apply(this, arguments);
	}
	
	
   }		
)(jQuery)